﻿using Darius.API.Application.Commands.Import;
using Darius.API.Application.Commands.Order;
using IMES.Common.Domain.SirModel;
using IMES.Common.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Darius.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrdersController : ControllerBase
    {
        private readonly IMediator mediator;

        public OrdersController(IMediator mediator) 
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 下订单
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> CreateOrder(OrderCreateCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SearchOrder(OrderSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> DeleteOrder(OrderDetailDeleteCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 查询产品信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultPage<Product>> SearchProduct(ProductSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 选中的产品信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultT<Product>> ProductCheck(ProductShowCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 订单导出
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> OrderImport([FromQuery] FileImportCommand cmd)
        {
            var result=await mediator.Send(cmd);
            return File(result.FileBytes, result.MimeType, result.FileName);
        }
        /// <summary>
        /// 导入产品明细
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> OrderExpoert(FileExportCommand cmd)
        {
            var result=await mediator.Send(cmd);
            return result;
        }
        /// <summary>
        /// 获取订单产品明细
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetOrderProduct(OrderProductSearchCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 获取订单产品明细
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultT<GetOrderDto>> GetOrderPro(OrderProGetCommand cmd)
        {
            return await mediator.Send(cmd);
        }

    }
}
